package pl.diagnoser.server.persistance.map;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "D_ATTRIBUTE")
public class AttributeDict implements Serializable {

	private static final long serialVersionUID = 1L;
	private Long attributeID;
	private String attributeName;
	private int isDate;
	private int isMultiple;
	private int isFile;
	private Set<AttributeValuesDict> attributeValuesDict = new HashSet<AttributeValuesDict>(0);
	private App app;
	
	public AttributeDict() {}
	/*
	public AttributeDict(String attributeName) {
		this.attributeName = attributeName;
	}
	*/
	public AttributeDict(String attributeName, int isDate, int isMultiple, int isFile, App app) {
		this.attributeName = attributeName;
		this.isDate = isDate;
		this.isMultiple = isMultiple;
		this.isFile = isFile;
		this.app = app;
	}
	public AttributeDict(String attributeName, Set<AttributeValuesDict> attributeValues) {
		this.attributeName = attributeName;
		this.attributeValuesDict = attributeValues;
	}
	
	@Id
	@GeneratedValue
	@Column( name = "ATTRIBUTE_ID", unique = true, nullable = false, length = 10 )
	public Long getAttributeID() {
		return attributeID;
	}
	
	public void setAttributeID(Long attributeID) {
		this.attributeID = attributeID;
	}

	@Column( name = "ATTRIBUTE_NAME", unique = true, nullable = false, length = 255 )
	public String getAttributeName() {
		return attributeName;
	}
	
	public void setAttributeName(String attributeName) {
		this.attributeName = attributeName;
	}
	
	@Column( name = "IS_DATE", unique = false, nullable = false, length = 1 )
	public int getIsDate() {
		return isDate;
	}
	
	public void setIsDate(int isDate) {
		this.isDate = isDate;
	}
	
	@Column( name = "IS_MULTIPLE", unique = false, nullable = false, length = 1 )
	public int getIsMultiple() {
		return isMultiple;
	}
	
	public void setIsMultiple(int isMultiple) {
		this.isMultiple = isMultiple;
	}
	
	@Column( name = "IS_FILE", unique = false, nullable = false, length = 1 )
	public int getIsFile() {
		return isFile;
	}
	
	public void setIsFile(int isFile) {
		this.isFile = isFile;
	}
	
	@ManyToMany(cascade = CascadeType.ALL)
	@JoinTable(name = "T_ATTRIBUTE_VALUES", joinColumns = { @JoinColumn(name = "ATTRIBUTE_ID") }, inverseJoinColumns = { @JoinColumn(name = "ATTRIBUTE_VALUE_ID") })
	public Set<AttributeValuesDict> getAttributeValuesDict() {
		return attributeValuesDict;
	}
	
	public void setAttributeValuesDict(Set<AttributeValuesDict> attributeValues) {
		this.attributeValuesDict = attributeValues;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="APP_ID")
	public App getApp() {
		return app;
	}
	public void setApp(App app) {
		this.app = app;
	}
}
